package com.sne.monitor.controller;

import com.sne.common.entity.Result;
import com.sne.monitor.service.IMonitorUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Size;
import java.util.List;

/**
 * 用户在线统计controller
 * @author fanghh
 * @date 2020/11/23
 */
@Validated
@RestController
@RequestMapping("/monitor/monitor-user")
@Api(tags = "在线统计")
public class MonitorUserController {

    @Autowired
    private IMonitorUserService iMonitorUserService;

    @PreAuthorize("hasAuthority('monitor:user:list')")
    @ApiOperation(value = "在线用户列表")
    @GetMapping("/list")
    public Result list() {
        return Result.success(iMonitorUserService.list());
    }

    @PreAuthorize("hasAuthority('monitor:user:delete')")
    @ApiOperation(value = "强退")
    @DeleteMapping("/delete/{token}")
    public Result delete(@PathVariable String token) {
        return Result.success(iMonitorUserService.deleteByToken(token));
    }

    @PreAuthorize("hasAuthority('monitor:user:deleteIds')")
    @ApiOperation(value = "强退多个用户")
    @DeleteMapping("/deleteIds")
    public Result deleteIds(@RequestBody @Size(min = 1,message = "tokens不能为空") List<String> tokens) {
        return Result.success(iMonitorUserService.deleteByTokens(tokens));
    }

}
